import {PageContainer} from "@ant-design/pro-components";
import SocialUserTable from "@/pages/SocialUser/components/SocialUserTable";
import {SocialUserVO, saveSocialUser, updateSocialUser} from "@/services/SocialUserService";
import SocialUserUpdateModal from "@/pages/SocialUser/components/SocialUserUpdateModal";
import {useRef, useState} from "react";
import {message} from "antd";
import {ActionType} from "@ant-design/pro-table";
import {useSnapshot} from "@@/exports";
import {SocialUserModel} from "@/models/socialUser";


const SocialUser = () => {
    // 表格引用
    const tableRef = useRef<ActionType>()
    let socialUserState = useSnapshot(SocialUserModel.state);

    // 提交修改
    const onUpdateFinish = async (formData: any) => {
        let dto: SocialUserVO = JSON.parse(JSON.stringify(formData))
        // 字段处理

        let func = socialUserState.socialUser ? updateSocialUser : saveSocialUser
        if (await func(dto)) {
            message.success("操作成功");
            // 刷新表格
            tableRef.current?.reload();
            return true;
        }
        return false;
    }

    return <PageContainer title="社交用户">
        {/*社交用户表格 开始*/}
        <SocialUserTable tableRef={tableRef} />
        {/*社交用户表格 结束*/}

        {/*修改模态框 开始*/}
        <SocialUserUpdateModal onFinish={onUpdateFinish}/>
        {/*修改模态框 结束*/}
    </PageContainer>
}

export default SocialUser
